package com.orhon.smartcampus.modules.notice.entity;

import com.orhon.smartcampus.modules.base.entity.Schools;
import com.orhon.smartcampus.modules.user.entity.Users;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Setter
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "base_notice", schema = "smartcloud", catalog = "")
public class Notice {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;

//    @OneToOne( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
//    @JoinColumn(name = "user_id")
//    @NotFound(action= NotFoundAction.IGNORE)
//    @Where(clause = "ISNULL(deleted_at)")
//    private Users user;

    @Column(name = "notice_title", nullable = true, length = 255)
    private String noticeTitle;

    @Column(name = "notice_content", nullable = true, length = 255)
    private String noticeContent;

    @Column(name = "sending_time", nullable = true, length = 255)
    private String sendingTime;

    @Column(name = "created_at", nullable = true)
    private Date createdAt;

    @Column(name = "created_by", nullable = true)
    private Integer createdBy;

    @Column(name = "updated_at", nullable = true)
    private Date updatedAt;

    @Column(name = "updated_by", nullable = true)
    private Integer updatedBy;

    @Column(name = "deleted_at", nullable = true)
    private Date deletedAt;

    @ManyToOne
    @JoinColumn(name = "school_id", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
    @Where(clause = "ISNULL(deleted_at)")
    private Schools baseSchoolsBySchoolId;

    @ManyToMany(cascade = CascadeType.ALL,  fetch = FetchType.LAZY)
    @JoinTable(
            name = "base_notice_school_relation",
            joinColumns = { @JoinColumn(name = "notice_id")},
            inverseJoinColumns = { @JoinColumn(name = "school_id")}
    )
    @NotFound(action= NotFoundAction.IGNORE)
    @Where(clause = "ISNULL(deleted_at)")
    List<Schools> schools;

//    @ManyToOne
//    @JoinColumn(name = "user_id", referencedColumnName = "id")
//    @NotFound(action=NotFoundAction.IGNORE)
//    @Where(clause = "ISNULL(deleted_at)")
//    private Users userUsersByUserId;
}
